<{include file="admin/head.html"}>
<link rel="stylesheet" href="<{$smarty.const.__URL__}>plugins/tablecloth/tablecloth.css">
<body>
	<{include file="admin/nav.html"}>
	<div id="content">
		<div id="sidebar">
			<ul>
				<li><a href="category.php">分类管理</a></li>
				<li><a href="article.php?do=list">文章管理</a></li>
				<li><a href="article.php?do=add">添加文章</a></li>
			</ul>
		</div>
		<div id="main">
			<h2 id="page_title">分类管理</h2>
				<{if $list}>
				<table>
					<tr>
						<th>ID</th>
						<th>名称</th>
						<th>上级分类</th>
						<th>操作</th>
					</tr>
					<{foreach from=$list item=l}>
					<tr id="row_<{$l.id}>">
						<td class="cell_id"><{$l.id}></td>
						<td class="cell_name"><{$l.name}></td>
						<td class="cell_parent">
							<{$l.pname|default:"无"}>
							<input type="hidden" name="pid" value="<{$l.pid}>">
						</td>
						<td>
							<a href="javascript:;" class="ln_edit" data="<{$l.id}>">修改</a>
							<a href="javascript:;" class="ln_del" data="{'url':'category.php?do=delCat&id=<{$l.id}>','to':'category.php'}">删除</a>
						</td>
					</tr>
					<{/foreach}>
				</table>
				<{else}>
					<div class="no_data">暂无数据</div>
				<{/if}>
				<div class="multi_op_form">
					<form method="post" enctype="multipart/form-data">
						<fieldset>
							<legend>添加分类</legend>
							<div class="row">
								<label for="name" class="row_left">名称</label>
								<input id="txt_name" type="text" name="name" class="row_right">
							</div>
							<div class="row">
								<label for="pid" class="row_left">上级分类</label>
								<select id="sel_pid" name="pid">
									<option value="0">无</option>
									<{foreach from=$list item=l}>
									<option value="<{$l.id}>"><{$l.name}></option>
									<{/foreach}>
								</select>
							</div>
							<div class="row">
								<input type="submit" value="提交" name="submit">
								<input id="btn_reset" type="reset" value="重置">
								<input id="do" type="hidden" name="do" value="<{$do|default:'addCat'}>">
								<input id="txt_id" type="hidden" name="id" value="<{$id}>">
							</div>					
						</fieldset>
					</form>
				</div>
		</div>
	</div>
	<script type="text/javascript" src="<{$smarty.const.__URL__}>plugins/tablecloth/tablecloth.js"></script>
	<{include file="admin/hasLightbox.html"}>
	<script type="text/javascript">
	$(document).ready(function(){
		$('.ln_edit').click(function(){
			var id = $(this).attr('data');
			var cname = $('#row_'+id+' .cell_name').text();
			var pid = $('#row_'+id+' .cell_parent input').val();
			$('#txt_id').val(id);
			$('#txt_name').val(cname);
			$('#sel_pid').val(pid);
			$('#do').val('editCat');
			$('.multi_op_form form').css('background','#BCE774');
			$('.multi_op_form legend').text('修改分类');
			setTimeout(function(){$('.multi_op_form form').css('background','');},300)
		})

		$('#btn_reset').click(function(){
			$('#do').val('addCat');	
			$('.multi_op_form legend').text('添加分类');
		})
	})
	</script>
</body>
</html>